<template>
	<view class="content pc-tou-gao " >
		<view class="scroll-fix" >

			<view class="d-kuan-juzhong ">
				<!--头部-->
				<view class="d-kuan pc-dingbu ">
					<DToubu 
					@login-success="handleLoginSuccess" 
					@logout-success="handleLogout"
					:dengluxianshi="denglu_xianshi"
					@update-dengluxianshi="handleUpdateDengluxianshi"
					@www-data="wwwdataget"
					></DToubu>
					
				</view>
				


				<!--头部-->
				<!--下面内容-->
				<view class="d-kuan d-clear">
					<uv-row customStyle="margin-bottom: 10px" :gutter="10">
						<!-- #ifdef H5 -->
						<uv-col span="2" class="pc-yincang">
							<!--左边导航-->
							<view class="d-daohang d-you-10 pc-yincang d-y-gundong d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight}">
								<view class="d-daohang-5 " >
									<Ddaohang 
									@denglu-fabu="denglu_fabu"
									
									></Ddaohang>
								</view>
							</view>
						</uv-col>
						<!-- #endif -->

						<uv-col :span="kuan_shu">
							
							<view class="d-shang-50">
								<view class="d-waikuang-20-0 d-beijing-bai ">
									<!--头部-->
									<Dfanhui
									:title="'钱包'"
									>

									</Dfanhui>
									<view class="d-neikuang-40">
										<view class="d-kuan d-juzhong d-wenzi-30 d-jiacu" style="color: #6a488a;">
											{{ u_data.wo && u_data.wo.money }}
										</view>
									</view>
									<view class="d-kuan">
										<view class="d-kuan d-juzhong d-wenzi-20 " style="color: #6a488a; line-height: 50px; background-color: #f4edf7;">
											<text decode="true" class="voucher_center__47">充值金额</text>
										</view>
										<view class="d-kuan d-juzhong d-wenzi-20 " style="color: #6a488a;line-height: 50px;background-color: #f4edf7;">
											
											<view class="" style="line-height: 50px;">
												<!--text decode="true" class="voucher_center__49">￥</text-->
												<input :value="money" @input="money_input" @tap="openKeyBoard('number')" class="" style="text-align:center; line-height: 50px;height: 50px;font-size: 26px;background-color: #f4edf7;" placeholder="￥0.00" placeholder-style="text-align:center" @focus="noKeybord" />
											
											</view>

										</view>
									

										<view class="voucher_center__1 d-shang-30">
											<!--判断是否在微信浏览器 并且是h5 微信浏览器:h5_weixin=1 是手机端 -->
											<view v-if="h5_weixin==0">
												
												<button  v-on:click="btSubmit_21_click()" class="btSubmit" :style="{ backgroundColor: chongzhi_title_zhi === 1 ? '#fd4542' : '#5a2e5d' }">
													{{ chongzhi_title }}
												</button>
											</view>
											<view v-else>
												<view v-if="u_data && u_data.bang_weixin == 1">
													<button  v-on:click="btSubmit_21_click()" class="btSubmit" :style="{ backgroundColor: chongzhi_title_zhi === 1 ? '#fd4542' : '#5a2e5d' }">
														{{ chongzhi_title }}
													</button>
												</view>
												<view v-else>
													<button  v-on:click="bang_weixin()" class="btSubmit d-shang-10" :style="{ backgroundColor: chongzhi_title_zhi === 1 ? '#fd4542' : '#5a2e5d' }">
														先绑定微信 后充值
													</button>
												</view>
												
											</view>
											

											<radio-group @change="payType_change" class="payType d-buhuanhang">
												<image v-on:click="voucher_center__55_55_click()"  src="/static/images/voucher_center__55_55.jpg" mode="scaleToFill" border="0"    class="voucher_center__55"></image>
												<text decode="true" class="voucher_center__56">微信</text>
												<radio value="wx"  class="voucher_center__57" checked>
												</radio>
												<!--image v-on:click="voucher_center__58_58_click()"  src="/static/images/voucher_center__58_58.jpg" mode="scaleToFill" border="0"    class="voucher_center__58"></image>
												<text decode="true" class="voucher_center__59">支付宝</text>
												<radio value="zfb"  class="voucher_center__60">
												</radio-->
											</radio-group>

											<view class="ymBbottom"></view>
											<!-- 数字键盘 -->
											<keyboard ref="number"   @onInput="onInput" @onDelete="onDelete" @onConfirm="onConfirm" :disableDot="true"/>

										</view>
										
										
										
										
									</view>
								</view>
								

							</view>
							
							
							
															
							
							<view class="pc-neikuang-20-list" >
								
							</view>
							
							<!--头部背景-->
							
							
						</uv-col>
						<!-- #ifdef H5 -->
						<uv-col span="3" class="pc-yincang">
							<view class="d-daohang d-you-10 pc-yincang d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight}">
								<view class="d-you-kuang">
									
								</view>
							</view>
						</uv-col>
						<!-- #endif -->
					</uv-row>

					

				</view>
				<!--下面内容-->


			</view>

			<view class="d-clear"></view>
		
		</view>
		<Dzhifu
		:show="show_zhifu"
		:payType="payType_zhifu"
		:jine="jine"
		@close="show_zhifu = false"
		@uidapi="getu_api"
		></Dzhifu>
		
		

	</view>
</template>

<script>
    import Api from '@/utils/api.js'; 
	import QuanApi from '@/utils/quan_api.js';
	import UApi from '@/utils/u_api.js';
	import { getRequest,postRequest } from '@/utils/wxRequest.js';
    //引入组件 d-toubu
    import DToubu from '@/components/d-toubu/d-toubu.vue'
	import Ddaohang from '@/components/d-daohang/d-daohang.vue'
	import Dweibu from '@/components/d-weibu/d-weibu.vue'
	import Dfanhui from '@/components/d-fanhui/d-fanhui.vue'
	import keyboard from "@/components/keyboard-package/keyboard-package";
	import Dzhifu from '@/components/d-zhifu/d-zhifu.vue'
	
	export default {
		data() {
			return {
				title: 'Hello',
				leftNavHeight: '500rpx', // 默认高度
                rightColWidth: '300px', // 默认宽度
				rightColLeft: '0px', // 添加这个属性
				uiddata:{},
				erjidata:[],
				erjiindex:'',//当前激活的二级菜单索引
				activeIndex: -1, // 当前激活的一级菜单索引
				zhishi_tuijian_data:[], // 知识推荐数据
				zhishi_daohang_list:[], // 知识导航列表
				zhishi_list:[], // 知识列表
				haibao_data:[], // 海报数据
				imageSize: {
        		    width: 0,
        		    height: 0
        		},
				tubiaolist: 
				['integral', 'kefuv-ermai', 'coupon', 'gift', 'scan',
					'pause-circle', 'volume-off', 'email', 'list'
				],
				denglu_xianshi:0, // 登录显示

				tiezi_list:[], // 帖子列表

				currentPage: 1, //下拉加载
    			pageSize: 12, //下拉加载
    			isLoading: false, //下拉加载
    			noMoreData: false, //下拉加载
				
				kuan_shu: 7, //格大小
				uid: '', // 用户ID - 初始化为空字符串，将在onLoad/onShow中设置
				swiperHeight: '250',
				gao: '20', //图片高度
				
				quan_data:[],
				
				shenhe_shu:0,//审核帖子数量
				u_data:[], // 用户信息
				dataLoaded: false,
			
				guanzhu_panduan:0,
				money:'',//充值金额
				payType:'wx',//单选框选中值
				errorMessage:'',
				pay:{},
				zhifuerweima:{},
				show: false,
				fanhuidata: false,
				fanhuiurl:'',
				wwwData:{},
				show_zhifu:false, // 支付弹窗
				payType_zhifu:'weixin', // 支付类型 1是支付宝，2是微信
				jine:0, // 金额
				chongzhi_title:'我要充值',
				chongzhi_title_zhi:0,
				h5_weixin:0, // 判断是否在微信浏览器 并且是h5
			}
		},
		components: {
  		    DToubu,
			Ddaohang,
			Dweibu,
			Dfanhui,
			keyboard,
			Dzhifu
  		},
		mounted() {

			// 确保在组件挂载后更新uid
			// console.log('Component mounted, checking uid...');
			const storeUid = this.$store.state.memberuid;
			if (storeUid && !this.uid) {
				this.uid = storeUid;
				// console.log('UID set from store in mounted:', this.uid);
			}
			
    	    
			this.getRightColWidth(); // 添加这行
    	    // 添加窗口大小变化监听
			// #ifdef H5
			this.setLeftNavHeight();
    	    window.addEventListener('resize', this.setLeftNavHeight);
			window.addEventListener('resize', this.getRightColWidth); // 添加窗口大小变化监听
			// #endif
			var e = this;
			//this.onImageLoad(e);
    	},
    	beforeDestroy() {
    	    // 移除监听
			// #ifdef H5
    	    window.removeEventListener('resize', this.setLeftNavHeight);
			window.removeEventListener('resize', this.getRightColWidth); // 添加这行
			// #endif
    	},
		onShow() {
			this.isH5Weixin();
			// console.log('Component shown, updating uid...');
			const storeUid = this.$store.state.memberuid;
			// console.log('Store memberuid:', storeUid);
			this.uid = storeUid;
			// console.log('UID set in onShow:', this.uid);

			if(!storeUid){
				// console.log('No uid in store, showing login prompt');
				this.denglu_xianshi = 1;
				this.godenglu(); // 暂时注释掉自动跳转，便于调试
			}
			// 分段是否有返回的url
			var fanhuiurl = uni.getStorageSync('fanhuiurl');
			
			if(fanhuiurl) {
				duixin.fanhuidata = true;
				duixin.fanhuiurl = fanhuiurl;
			}

			//this.getShenhe_shu_api();
			
		},
		onLoad(e) {
			// console.log('Component loaded with params:', e);
			// 优先使用路由参数中的uid
			if (e && e.uid) {
				this.uid = e.uid;
				// console.log('UID set from route params:', this.uid);
			} else {
				// 如果路由参数中没有uid，则从store获取
				const storeUid = this.$store.state.memberuid;
				if (storeUid) {
					this.uid = storeUid;
					// console.log('UID set from store in onLoad:', this.uid);
				} else {
					// console.log('No uid available in route params or store');
				}
			}
			
			// 只有在有uid的情况下才调用API
			if (this.uid) {
				this.getu_api();
				// 初始化昵称数据
				this.setInitialNicheng();
			
			} else {
				console.warn('Cannot call getu_api: uid is not available');
			}
			
		},
		computed: {
		  yidenglu() {
		    return (this.$store.state.memberuid && this.$store.state.keycode) ? 1 : 0;
		  },
		  touxiang() {
		    return this.$store.state.member? this.$store.state.member.avatar : '';
		  },
		  name1() {
		    return this.$store.state.member? this.$store.state.member.name : '';
		  },
		  pc() {
		    return this.$store.state.kuan.pc;
		  },
		},
		onReachBottom() {
  			//this.onReachBottom(); //下拉加载分页
  		},

		methods: {
			// 判断是否在微信浏览器 并且是H5：是则返回h5_weixin=1，否则返回h5_weixin=0
			isH5Weixin() {
				// #ifdef H5
				try {
					const ua = (typeof window !== 'undefined' && window.navigator) ? window.navigator.userAgent.toLowerCase() : '';
					const isWeixin = ua.indexOf('micromessenger') !== -1; // 微信内置浏览器
					const isMobile = /mobile|android|iphone/.test(ua);     // 手机端（不含iPad/PC）
					this.h5_weixin = (isWeixin && isMobile) ? 1 : 0;
					return this.h5_weixin;
				} catch (e) {
					this.h5_weixin = 0;
				}
				// #endif
				this.h5_weixin = 0;
				return 0;
			},
		    openKeyBoard(key) {
				this.type=key;
				this.$refs[key].open();
			},
			onInput(val){
				this.money += val;
				this.chongzhi_title = "确 认 充 值";
				this.chongzhi_title_zhi = 1;
				
				
				
				
				
			},  
			onDelete(){
				this.chongzhi_title = "我 要 充 值";
				this.chongzhi_title_zhi = 0;
				if (this.money.length > 0) {  
					this.money = this.money.slice(0, -1);  
				}
			},
			/**
			* btSubmit_21处理函数
			* 数据绑定  data-index="{{index}}" 
			* 数据取值  var index = e.currentTarget.dataset.index; var cata = this.list_cata_list[index];
			*/
			btSubmit_21_click:function(event){
				var duixin = this;
				  if(this.money==''){
					// 拉起数字键盘（使用自定义数字键盘组件）
                    uni.hideKeyboard();
					this.openKeyBoard('number'); // 打开自定义数字键盘
					//uni.showToast({title: '充值金额不能为空！',icon: 'none',duration: 2000});
					 return; 
				  } else if (this.payType==''){
					  uni.showToast({title: '充值方式不能为空！',icon: 'none',duration: 2000});
					 return; 
				  } else {
					  /*uni.showToast({title: '开始充值',icon: 'none',duration: 2000});
					  return; */
					  
					  duixin.chongzhipay();
				  }
			},
			/**
			* radio处理函数
			*/
			payType_change:function(event){
			    //console.log(event.target.value);
			    this.payType=event.target.value;
			},
			/**
			* input处理函数
			*/
			money_input:function(event){
				
			    this.money=event.target.value;
				const regex = /^\d+(\.\d{1,2})?$/; // 匹配整数或小数（最多两位小数)
				var value = this.money;
				if (!regex.test(this.money)) {  
					this.money = '';
					this.errorMessage = '请输入数字和点（.）';
					uni.showToast({title: '请输入数字',icon: 'none',duration: 2000});
					return; 
				// 清除非法输入，保持上一个合法值  
				//this.money = value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/\.$/, '');  
				} else {  
					this.errorMessage = '';  
				} 
			    //console.log(event.target.value);
			},
			close(){
				this.show = false;
			},
			open(){
				this.show = true;
			},
			noKeybord() {
				document.activeElement.blur(); // 禁止输入框对焦（禁止弹出原生键盘）
				uni.hideKeyboard();
			},
			//图片
			onImageLoad(e, index) {
				// 获取系统信息
				const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowHeight = systemInfo.windowWidth;
				if(windowHeight >=920){
					var gao = 30;
					
				} else {
					var gao = 0;
				}


				this.$nextTick(() => {
        		    const query = uni.createSelectorQuery().in(this);
        		    query.select('#tupian-'+index).boundingClientRect(data => {
        		        if (data && data.width > 0 && data.height > 0) {
        		            this.$set(this.haibao_data[index], 'imageSize', {
        		                width: data.width,
        		                height: data.height + gao
        		            });
							// console.log('图片尺寸:', this.haibao_data[index].imageSize);
        		        } else {
        		            console.warn(`图片${index}尺寸获取失败`);
        		            this.$set(this.haibao_data[index], 'imageSize', {
        		                width: 300,
        		                height: 200
        		            });
        		        }
        		    }).exec();
        		});

    		},
			getRightColWidth() {
				// 获取系统信息
				const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowWidth = systemInfo.windowWidth;
				var d = this;

                this.$nextTick(() => {
				if(this.pc){
					d.gao = 20;
					d.kuan_shu = 7;
					d.swiperHeight = '250';
				} else {
					d.gao = 10;
					d.kuan_shu = 12;
					d.swiperHeight = '120';

				}
				// console.log('窗口高度:', windowWidth);

                /* const query = uni.createSelectorQuery().in(this);
                 query.select('#youbiankuan').boundingClientRect(rect => {
                   if (rect) {
                    
					 	this.rightColWidth = `${rect.width-80}px`;
                    	this.rightColLeft = `${rect.left}px`; // 计算左侧位置
                    	// console.log('右侧列位置:', this.rightColWidth);
                   }
                 }).exec();*/
               });
            },

			
			
			setLeftNavHeight() {
        	    // 获取系统信息
        	    const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowHeight = systemInfo.windowHeight;
        	    const headerHeight = 70; // 头部高度估计值
        	    const calculatedHeight = windowHeight - headerHeight;
				
        	    // 设置左边导航高度
        	    this.leftNavHeight = `${calculatedHeight}px`;
        	},
			
			
			handleLoginSuccess() {
  			  this.$forceUpdate();
  			},
			
			
			
			
			denglu_fabu(){
				if(this.yidenglu == 0){
					this.denglu_xianshi = 1;
					
				} else {
					this.denglu_xianshi = 0;
						
				}
				
				// console.log('发布登录',this.denglu_xianshi);
				
			},
			// 更新判断是否登录
			handleUpdateDengluxianshi(value) {
			  this.denglu_xianshi = value;
			  
			  // console.log('关闭登录',this.denglu_xianshi);
			},
			// 退出登录
			handleLogout() {
 			  
 			  this.godenglu(); // 暂时注释掉自动跳转，便于调试
			   
 			},
			
			
			
			
			
			//个人信息
			getu_api(){
				this.money = '';
				// console.log('Calling getu_api with uid:', this.uid);
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				const data = {
						uid: this.uid,
						api_auth_uid: this.uid,
						api_auth_code: keycode,
					}
				var get_data = getRequest(UApi.getU(),data);
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						if(this.uid){
							//this.u_data = res.data.data.wo;
						} else {
							//this.u_data = res.data.data.u;
						}
						this.u_data = res.data.data;
						//this.u_data = res.data.data;
						this.dataLoaded = true;
						
					}
				})

			},
			//跳转个人信息
			godenglu(){
				//保持url到缓存，名称是u_url
				uni.setStorageSync('go_url', this.$route.fullPath);
				uni.navigateTo({
					url: '/pages/u/denglu',
				})
			},
			//数字键盘的确定
			onConfirm(){
				// 关闭自定义数字键盘
				try {
					if (this.$refs.number && typeof this.$refs.number.close === 'function') {
						this.$refs.number.close();
					}
				} catch (e) {}
				// 双保险：隐藏原生键盘
				uni.hideKeyboard();
				
				// 金额校验（保留两位小数的数字）
				const regex = /^\d+(\.\d{1,2})?$/;
				if (!this.money || !regex.test(this.money)) {
					uni.showToast({ title: '请输入有效金额', icon: 'none', duration: 1500 });
					return;
				}
				// 更新按钮文案与样式为“确认充值”
				this.chongzhi_title = '确 认 充 值';
				this.chongzhi_title_zhi = 1;
				
				// 显示加载提示
				/*uni.showLoading({ title: '加载中...', mask: true });
				// 短暂延时后关闭（仅作为点击反馈，不触发支付）
				setTimeout(() => {
					uni.hideLoading();
				}, 4000);*/
				
				// 触发按钮的同一充值流程
				
				this.btSubmit_21_click();
				
				
				
				
				
			},

			tuichu(){
				uni.showToast({
					title: "退出成功",
					icon: 'success',
					
				})

				uni.removeStorageSync('userInfo');
				uni.removeStorageSync('memberuid');
				uni.removeStorageSync('keycode');
				uni.removeStorageSync('member');
				// 通过 mutations 更新 Vuex 状态
				this.$store.commit('setMember', {});
    			this.$store.commit('setMemberUid', '');
    			this.$store.commit('setKeycode', '');
				//this.yidenglu = 0;
				// 触发退出事件
				this.$emit('logout-success');
				//退出跳转到首页
				uni.reLaunch({ url: "/pages/index/index" });
			},
			// 设置初始昵称
			setInitialNicheng() {
				if(this.u_data && this.u_data.wo && this.u_data.wo.name && !this.uiddata.nicheng){
					this.uiddata.nicheng = this.u_data.wo.name;
				}
			},
			// 昵称设置
			d_shezhi() {
				var duixin = this;
				var nicheng = duixin.uiddata && duixin.uiddata.nicheng;
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				var datas = "&is_ajax=1&data[name]="+nicheng;
				var postRenzhengRequest = postRequest(Api.postZiliao(uid,keycode),datas);
					postRenzhengRequest.then(response => {
						if (response.data.code == 1) {
							
							uni.showToast({
								title: response.data.msg,
								icon: 'success',
								success: function () {
								}
							});
							this.getu_api();
						} else {
							uni.showToast({
								title: response.data.msg,
								icon: 'error',
							});
						}
					});
			},
			// 充值
			chongzhipay(){
				uni.showLoading({ title: '加载中...', mask: true });
				// 短暂延时后关闭（仅作为点击反馈，不触发支付）
				setTimeout(() => {
					uni.hideLoading();
				}, 3000);
				/*uni.showToast({title: '开始充值',icon: 'none',duration: 2000});
				return;*/
				var duixin = this; 
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				var money = this.money;
				// #ifdef H5
				const userAgent = navigator.userAgent.toLowerCase();
				if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android/.test(userAgent)) {
					// 移动端
					//console.log('移动端',userAgent)
					var h5datas = "is_ajax=1&pay[mark]=recharge&pay[money]=" + money + "&pay[type]=weixin&pay[is_xcx]=1&h5=1";
					//判断是否在微信浏览器中
                    if(/micromessenger/.test(userAgent)){
						// 微信浏览器中
						//console.log('移动端',userAgent)
						var h5datas = "is_ajax=1&pay[mark]=recharge&pay[money]=" + money + "&pay[type]=weixin&pay[is_xcx]=1&h5=1";
						duixin.jine = money;
					} else {
						duixin.jine = money;
						duixin.show_zhifu = true;
						return;
					}
				} else {
					// pc端
					//console.log('PC端',userAgent)
					//var h5datas = "is_ajax=1&pay[mark]=recharge&pay[money]=" + money + "&h5=2";
					// 弹出 Dzhifu 组件
					duixin.show_zhifu = true;
					duixin.jine = money;
					return;
				}
				// #endif
				
			
				var datas = "is_ajax=1&pay[mark]=recharge&pay[money]=" + money + "&pay[type]=weixin&pay[is_xcx]=1";
				
				var postPayRequest = postRequest(Api.postPay(uid,keycode),datas);
				postPayRequest.then(response => {
					if (response.data.code) {
						//console.log('弹出0'); 
						// #ifdef MP
						duixin.getPayzhifu(response.data,datas);
						// #endif
						// #ifdef H5
						duixin.getPayzhifu(response.data,h5datas);
						// #endif
						
						
					} else {
						uni.showToast({
							icon: 'none',
							title: response.data.msg,
							duration: 1000
						});
					}
				});
			},
			// 拉起支付
			getPayzhifu(data,urldata){
				//console.log('弹出2');
				var duixin = this; 
				// #ifdef MP
				var getPayidRequest = getRequest(Api.getPayid(data.code,urldata));
				// #endif
				// #ifdef H5
				var getPayidRequest = getRequest(Api.getPayid(data.code,urldata));
				// #endif
				getPayidRequest.then(response => {
					//console.log('支付weixin',response); 
					if (response.data.code) {
						// #ifdef H5
							//duixin.getH5payzhifu(response.data.data,urldata);
							duixin.getWeixinMiyueData(response.data.data);
							if(response.data.data && response.data.data.pc == 1){
								duixin.zhifuerweima = response.data.data;
								duixin.show_zhifu = true;
							}
						// #endif
						// #ifdef MP
						// 小程序
						wx.requestPayment({
							"timeStamp": response.data.data.timeStamp,
							"nonceStr": response.data.data.nonceStr,
							"package": response.data.data.package,
							"signType": "MD5",
							"paySign": response.data.data.paySign,
							"success":function(res){
								duixin.getMemberpay(res);
								duixin.getu_api();
								const targetUrl = uni.getStorageSync('goumai_jifen_url') || duixin.fanhuiurl;
								if (targetUrl && /^\/pages\/[^/]+\/[^/]+/.test(targetUrl)) {
									uni.navigateTo({ url: targetUrl });
								} else {
									// 兜底：无效或空的返回地址，跳转到首页
									uni.reLaunch({ url: '/pages/index/index' });
								}
								/*if(duixin.fanhuiurl){
								    uni.reLaunch({ url: duixin.fanhuiurl });
								}*/
							},
							"fail":function(res){
								//console.log(res);
								wx.showModal({
									showCancel: false,
									content: res.err_desc+"："+res.errMsg
								})
							}
							
						})
						// #endif
					  //console.log('支付',response.data); 
					  //duixin.quanzishuxing = response.data.data
					} else {
					  uni.showToast({
					  	icon: 'none',
					  	title: response.data.msg,
					  	duration: 1000
					  });
					}
				});
			},
			
			async getWeixinMiyueData(data){
				
				var duixin = this;
				// #ifdef H5
				try {
					await this.$ensureWxLoaded();
				} catch (e) {
					console.error('JSSDK加载失败：', e);
					uni.showToast({ title: '微信JSSDK加载失败', icon: 'none' });
					return;
				}
				// #endif
				// #ifdef H5
				const wxRef = window.wx || (window.duixin && window.duixin.$wx);
				if (!wxRef || typeof wxRef.config !== 'function') {
					console.error('微信JSSDK未正确加载：wxRef.config 不可用', wxRef);
					uni.showToast({ title: '微信JSSDK不可用', icon: 'none' });
					return;
				}
				// #endif
				var danqianurls = uni.getLaunchOptionsSync();
				//var danqianurls = '/'+danqianurls.path+'?id='+danqianurls.query.id;
				var danqianurls = '/'+danqianurls.path;
				
				const url = decodeURIComponent(window.location.href);
				var urljia = danqianurls;
				
				var getWeixinmiyueRequest = getRequest(Api.getWeixinfengxiangmiyue(url));
				 
				getWeixinmiyueRequest.then(response => {
					
					if (response.data.code == 1) {
						
						var weixin = response.data.data;
						//console.log('充值H5weixin',weixin);
						wxRef.config({
						  debug: false,//true
						  appId: weixin.appId,
						  timestamp: weixin.timestamp,
						  nonceStr: weixin.nonceStr,
						  signature: weixin.signature,
						  jsApiList: [
						    // 所有要调用的 API 都要加到这个列表中
						    
						    // 这里需要自己按微信文档来写参数
						    "updateAppMessageShareData", 
							"updateTimelineShareData",
							'checkJsApi', //判断当前客户端版本是否支持指定JS接口  
							'onMenuShareAppMessage', //分享接口  
							'getLocation', //获取位置  
							'openLocation', //打开位置  
							'scanQRCode', //扫一扫接口  
							'chooseWXPay', //微信支付  
							'chooseImage', //拍照或从手机相册中选图接口  
							'previewImage', //预览图片接口  
							'uploadImage' //上传图片  
						  ]
						});
						wxRef.ready(function () {
							//duixin.getPayzhifu(dataa,datab);
							//console.log('支付data',data); 
							
							// config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
							wxRef.checkJsApi({
								jsApiList: ['chooseWXPay'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
								success: function(res) {
									//console.log('支付res',res); 
								}
							});
							// 调用微信支付接口
							wxRef.chooseWXPay({
								timestamp: data.timeStamp,    // 时间戳
								nonceStr: data.nonceStr,      // 随机串
								package: data.package,        // 订单详情扩展字符串
								signType: 'MD5',                // 签名方式
								paySign: data.paySign,           // 签名
								success: function(res) {
									// 支付成功后的回调函数
									duixin.getMemberpay(res);
									duixin.getu_api();
									//判断 goumai_jifen_url 是否存在
									if(uni.getStorageSync('goumai_jifen_url')){
									    uni.navigateTo({ url: uni.getStorageSync('goumai_jifen_url') });
									} else {
										uni.navigateTo({ url: duixin.fanhuiurl });
									}
									/*if(duixin.fanhuiurl){
									    uni.reLaunch({ url: duixin.fanhuiurl });
									}*/
								},
								fail: function(res) {
									// 支付失败后的回调函数
									console.error('Payment failed', res);
									
									setTimeout(() => {
										uni.reLaunch({
											//url: '/pages/fail/fail'
										})
									}, 500)
								}
							})
							
						});
						wxRef.error(function(res){
						  //console.log('weixinres',res); 
						});
					} else {
					    duixin.setData({
							displaySwiper: "none"
					    });
					}
				});
			},
			//拉起会员
			getMemberpay(data){
				var duixin = this;
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				var getMemberidRequest = getRequest(Api.getMemberid(uid,keycode));
				getMemberidRequest.then(res => {
					if (res.data.code == 1) {
						uni.showModal({
							showCancel: false,
							success: function (res) {
							  if (res.confirm) {
								if(uni.getStorageSync('goumai_jifen_url')){
								    uni.navigateTo({ url: uni.getStorageSync('goumai_jifen_url') });
								} else {
									uni.navigateTo({ url: duixin.fanhuiurl });
								}
								    /*if(duixin.fanhuiurl){
									    uni.reLaunch({ url: duixin.fanhuiurl });
								    }*/
								
							  }
							},
							content: "付款成功"
					    });
					}
				});
			},
			wwwdataget(e){
				this.wwwData = e;
			},
			// 先绑定 微信后充值
			bang_weixin(){
				uni.navigateTo({ url: '/pages/u/bangweixin' });
				
			},







		}
	}
</script>

<style>
/*引入css main.css*/

	.content {
		
		
		display: flex;
		flex-direction: column;
		/*align-items: center;*/
		
		background-color: #f3f3f3;
		
		margin-bottom: 0px;
		
		/*height: 100vh;*//* 添加全屏 */
		/*width: 100vw;*/ /* 添加全屏*/
		box-sizing: border-box;
		overflow-x: hidden;

		
		

	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	/* 屏幕宽度大于786px时隐藏uni-page-head */
    @media (min-width: 786px) {
        uni-page-head {
            display: none !important;
            opacity: 0 !important;
            height: 0 !important;
            visibility: hidden !important;
        }
    }
	/*.d-daohang{
		
		width: 600rpx;
	}*/
	/* 添加在style部分 */
	.d-daohang-zuo {
    position: fixed;
    left: 0;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #f5f5f5;
    z-index: 100;
	box-shadow: 2px 0 5px rgba(177, 177, 177, 0.1);
  }
  
  .d-daohang-you {
    position: fixed;
    left: 180rpx;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #fff;
    z-index: 100;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
  }
  .d-erji-item {
    height: 60rpx;
    line-height: 60rpx;
    padding: 0 20rpx;
   /* border-bottom: 1px solid #f0f0f0;*/
  }
  
  .d-erji-item:active {
    background: #f5f5f5;
  }
  .you-guding {
	position: fixed;
	top: 0; /* 根据头部高度调整 */
	/*box-shadow: -2px 0 5px rgba(0,0,0,0.1);*/
	transition: all 0.3s ease;
}
/* 大于786px时的样式 */
@media screen and (min-width: 1024px) {
	.d-bianhua-10 {
		padding: 30px;
	}
	.pc-zuo-520 {
		margin-left: 520rpx;
	}
	.you-guding {
		position: fixed;
			
		top: 60px; /* 根据头部高度调整 */
		/*box-shadow: -2px 0 5px rgba(0,0,0,0.1);*/
		transition: all 0.3s ease;
	}
		
	
}
    uni-page-body,#app {height: 100%;}
	button::after {border: none;width: auto;}
	input{outline: none;border: none;list-style: none;width: auto;}
	.list_item{float: left;}
	.ym_hide{display: none;}
	.ym_show{display: block;}
	.slide-image {  width: 100%;  height:100%;}
	.list_horizontal {width: auto; display:inline-block; }
	.voucher_center__1{white-space:normal;width:100%;height:1510upx;padding:0upx;clear:both;float:left; border-radius:0upx;font-size:8upx;}
	.voucher_center__1 .voucher_center__47{white-space:normal;width:181upx;height:34upx;padding:0upx;clear:both;margin:29upx auto 0;display:block;float:none; border-radius:0upx; color:#646464;font-size:34upx; line-height:34upx; text-align:center;}
	.voucher_center__1 .voucher_center__48{white-space:normal;width:647upx;height:44upx;padding:0upx;clear:both;margin:68upx auto 0;display:flex;justify-content:center;align-items:center; border-radius:0upx;font-size:43upx; line-height:44upx;}
	.voucher_center__1 .voucher_center__48 .voucher_center__49{white-space:normal;width:auto;height:44upx;padding:0upx;margin:0 10upx 0 0;display:inline-block; border-radius:0upx; color:#646464;font-size:43upx; line-height:44upx;}
	.voucher_center__1 .voucher_center__48 .money{white-space:normal;width:auto;height:50px;min-height:50px;padding:0upx;margin-top:0upx;display:inline-block; border-radius:10px; color:#ff0000;font-size:50upx; line-height:50px; text-align:center; background-color: #ffffff; caret-color: #ff0000;}
	.voucher_center__1 .payType{white-space:normal;width:683upx;height:50upx;padding:0upx;clear:both;margin-top:102upx;margin-left:auto;margin-right:auto;display:flex;justify-content:center;align-items:center; border-radius:0upx;font-size:49upx; line-height:50upx;}
	.voucher_center__1 .payType .voucher_center__55{white-space:normal;width:46upx;height:47upx;padding:0upx;margin-top:3upx;margin-left:0upx;margin-right:8upx;display:inline-block; border-radius:0upx;font-size:48upx; line-height:47upx;}
	.voucher_center__1 .payType .voucher_center__56{white-space:normal;width:61upx;height:28upx;padding:0upx;margin-top:11upx;margin-left:0upx;margin-right:8upx;display:inline-block; border-radius:0upx; color:#646464;font-size:27upx; line-height:28upx;}
	.voucher_center__1 .payType .voucher_center__57{white-space:normal;width:43upx;height:44upx;padding:0upx;margin-top:2upx;margin-left:0upx;margin-right:0upx;display:inline-block; border-radius:0upx;font-size:43upx; line-height:44upx;}
	.voucher_center__1 .payType .voucher_center__58{white-space:normal;width:47upx;height:47upx;padding:0upx;margin-top:3upx;margin-left:105upx;float:left; border-radius:0upx;font-size:49upx; line-height:47upx;}
	.voucher_center__1 .payType .voucher_center__59{white-space:normal;width:81upx;height:29upx;padding:0upx;margin-top:11upx;margin-left:22upx;float:left; border-radius:0upx; color:#646464;font-size:27upx; line-height:29upx;}
	.voucher_center__1 .payType .voucher_center__60{white-space:normal;width:43upx;height:43upx;padding:0upx;margin-top:3upx;margin-left:11upx;float:left; border-radius:0upx;font-size:42upx; line-height:43upx;}
	.voucher_center__1 .btSubmit{white-space:normal;width:300upx;height:90upx;padding:0upx;clear:both;margin:65upx auto 0;display:block;background-color:#5a2e5d;text-align:center;justify-content:center; border-radius:10upx; cursor:pointer; color:#ffffff;font-size:27upx; line-height:90upx; transform: translateY(0px);}
	.voucher_center__1 .voucher_center__22{white-space:normal;width:180upx;height:34upx;padding:0upx;clear:both;margin-top:76upx;margin-left:36upx;float:left; border-radius:0upx; color:#646464;font-size:31upx; line-height:34upx;}
	.voucher_center__1 .voucher_center__23{white-space:normal;width:677upx;height:365upx;padding:0upx;clear:both;margin-top:32upx;margin-left:36upx;float:left; border-radius:0upx; color:#c8c8c8;font-size:27upx; line-height:40upx;}
	.voucher_center__1 .voucher_center__66{white-space:normal;width:50%;height:34upx;padding:0upx;clear:both;margin-top:76upx;float:left; border-radius:0upx; color:#646464;font-size:31upx; line-height:34upx;}
</style>
